home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0793 / CSTRTEST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-01  |  2KB  |  68 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 263 of 335
  3. From : Todd Holmes                         1:152/5.0            29 Jun 93  08:52
  4. To   : Dj Murdoch
  5. Subj : Unit Cstr: Nul term strings for streams
  6. ────────────────────────────────────────────────────────────────────────────────}
  7. Program CstrTest;  {_Tested !!}
  8. {Demostrates the use of CStr.Pas}
  9.  
  10. Uses Objects,Cstr;
  11. Var
  12.    Stream: PStream;
  13.    I: integer;
  14.    PS: String;
  15.  
  16. Procedure PrintStream(S:PStream);
  17. {Prints all nul strings in the stream, assumes that the stream contains
  18.  valid data}
  19.  begin
  20.   Repeat
  21.    Writeln(LoadPStr(S^)); {Load a Cstr and converts it to a Pas string}
  22.   Until S^.GetPos = S^.GetSize;
  23.  end;
  24.  
  25. Function InitStream:PStream;
  26. {Shows how easy it is to copy a file to EMS if available}
  27.  
  28. Var Buf,EMS: PStream;
  29.  begin
  30.    Buf := New(PBufStream,Init('Test.txt',stOpenRead,512)); {Open BufStream}
  31.    Ems := New(PEmsStream,Init(Buf^.GetSize,Buf^.GetSize)); {Open EMSstream}
  32.    If Ems^.Status = stOk then begin  {if status <> ok then probly no ems}
  33.      Writeln('Using EMS.............');
  34.      Ems^.CopyFrom(Buf^,Buf^.GetSize); {Copy entire file to ems}
  35.      Ems^.Seek(0);                     {Reset Ems}
  36.      Dispose(Buf,Done);                {Get rid of buf}
  37.      Buf := Ems;
  38.     end
  39.    Else begin
  40.      Writeln('Bummer..time to upgrade?... Using Dos.......');
  41.      Dispose(Ems,Done);
  42.     end;
  43.  
  44.    InitStream := Buf; {note: this could be EMS or Buf, isn't OOP great!}
  45.  end;
  46.  
  47. begin
  48.   {CStrBuff has already create by the unit}
  49.   {Lets build our test file}
  50.   Stream:= New(PBufStream,Init('Test.txt',stCreate,512));
  51.   For I := 1 to 10 do begin
  52.     Str(I,PS);   {Converts Integer to String}
  53.     StorePstr(Stream^,PS); {Stores Pas string on the stream as a C String}
  54.    end;
  55.  Dispose(Stream,Done); {Shuts down the stream}
  56.  
  57.  Stream := InitStream;      {Sets stream up in EMS if Available}
  58.  PrintStream(Stream);       {Print contents of stream}
  59.  
  60.  InitCStrBuff(MaxCStrLen);  {change CStrBuff to 64k}
  61.  Stream^.Seek(0);           {Reset Stream}
  62.  Writeln;
  63.  Writeln('changed Cstrbuff size to : ',MaxStrLen);
  64.  Writeln;
  65.  PrintStream(Stream);
  66.  Dispose(Stream,Done);
  67.  DoneCStrBuff; {Remember to kill the buffer}
  68. end.